<template>
  <div>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="职称名称">
        <el-input v-model="formInline.atleName"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="show">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" @click="handleAdd">添加</el-button>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" @click="handleDel">删除</el-button>
      </el-form-item>
    </el-form>

    <el-table ref="multipleTable" :data="tableData" style="width: 100%">
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column label="编号" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.atle_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="职称名称" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.atle_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="产值比例" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.atle_pt_value }}</span>
        </template>
      </el-table-column>
      <el-table-column label="职称排序" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.atle_sort }}</span>
        </template>
      </el-table-column>
      <el-table-column label="职称描述" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.atle_describe }}</span>
        </template>
      </el-table-column>
      <el-table-column label="选择">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row.atle_id)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="职称添加" :visible.sync="dialogZiDianAddVisible">
      <el-form :model="form" :rules="rules" ref="form">
        <el-form-item label="职称名称" prop="atle_name">
          <el-input v-model="form.atle_name"></el-input>
        </el-form-item>
        <el-form-item label="产值比例" prop="atle_pt_value">
          <el-input v-model="form.atle_pt_value"></el-input>
        </el-form-item>
        <el-form-item label="职称排序" prop="atle_sort">
          <el-select v-model="form.atle_sort">
            <el-option label="" value="请选择"></el-option>
            <el-option label="1" value="1"></el-option>
            <el-option label="2" value="2"></el-option>
            <el-option label="3" value="3"></el-option>
            <el-option label="4" value="4"></el-option>
            <el-option label="5" value="5"></el-option>
            <el-option label="6" value="6"></el-option>
            <el-option label="7" value="7"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="职称描述" prop="atle_describe">
          <el-input v-model="form.atle_describe"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogZiDianAddVisible = false">取消</el-button>
        <el-button type="primary" @click="AddCun('form')">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="编辑" :visible.sync="dialogZiDianUpdateVisible">
      <el-form :model="bform" :rules="rules" ref="bform">
        <el-form-item label="ID" prop="atle_id">
          <span>{{ bform.atle_id }}</span>
        </el-form-item>
        <el-form-item label="职称名称" prop="atle_name">
          <el-input v-model="bform.atle_name"></el-input>
        </el-form-item>
        <el-form-item label="产值比例" prop="atle_pt_value">
          <el-input v-model="bform.atle_pt_value"></el-input>
        </el-form-item>
        <el-form-item label="职称排序" prop="atle_sort">
          <el-select v-model="bform.atle_sort">
            <el-option label="" value="请选择"></el-option>
            <el-option label="1" value="1"></el-option>
            <el-option label="2" value="2"></el-option>
            <el-option label="3" value="3"></el-option>
            <el-option label="4" value="4"></el-option>
            <el-option label="5" value="5"></el-option>
            <el-option label="6" value="6"></el-option>
            <el-option label="7" value="7"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="职称描述" prop="atle_describe">
          <el-input v-model="bform.atle_describe"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogZiDianUpdateVisible = false">取消</el-button>
        <el-button type="primary" @click="UpdateCun('bform')">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      formInline: {
        atleName: "",
        atle_pt_value: 0,
        atle_sort: 0,
        atle_describe: "",
      },
      form: {
        atle_id: "",
        atle_name: "",
        atle_pt_value: "",
        atle_sort: "",
        atle_describe: "",
      },
      bform: {
        atle_id: "",
        atle_name: "",
        atle_pt_value: "",
        atle_sort: "",
        atle_describe: "",
      },
      dialogZiDianAddVisible: false,
      dialogZiDianUpdateVisible: false,
      rules: {
        atle_name: [
          { required: true, message: "职称名称不能为空", trigger: "blur" },
        ],
        atle_pt_value: [
          { required: true, message: "分配比例不能为空", trigger: "blur" },
        ],
        atle_sort: [
          { required: true, message: "请选择职位排序", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.show();
  },
  methods: {
    show() {
      this.form = {};
      this.$axios
        .get(
          "http://localhost:20932/api/SystemManager/ArchitecturalTitle/GetArchitecturalTitleList?atleName=" +
            this.formInline.atleName
        )
        .then((r) => {
          if (r.status == 200) {
            this.tableData = r.data.list;
          }
        });
    },
    handleEdit(id) {
      this.dialogZiDianUpdateVisible = true;
      this.$axios
        .get(
          "http://localhost:20932/api/SystemManager/ArchitecturalTitle/GetArchitecturalTitleFan?id=" +
            id
        )
        .then((r) => {
          if (r.status == 200) {
            this.bform = r.data;
          }
        });
    },
    UpdateCun(bform) {
      this.$refs[bform].validate((valid) => {
        if (valid) {
          this.$axios
            .post(
              "http://localhost:20932/api/SystemManager/ArchitecturalTitle/GetArchitecturalTitleUpdate",
              this.bform
            )
            .then((r) => {
              if ((r.status == 200) & r.data) {
                this.$message("修改成功");
                this.dialogZiDianUpdateVisible = false;
                this.show();
              }
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
      // this.$axios
      //   .post(
      //     "http://localhost:20932/api/SystemManager/ArchitecturalTitle/GetArchitecturalTitleUpdate",
      //     this.bform
      //   )
      //   .then((r) => {
      //     if ((r.status == 200) & r.data) {
      //       this.$message("修改成功");
      //       this.dialogZiDianUpdateVisible = false;
      //       this.show();
      //     }
      //   });
    },
    handleAdd() {
      this.dialogZiDianAddVisible = true;
    },
    AddCun(form) {
      // if(this.form.atle_name=="")
      // {
      //   this.$message("职称名称不能为空");
      //   return;
      // }
      this.$refs[form].validate((valid) => {
        if (valid) {
          this.$axios
            .post(
              "http://localhost:20932/api/SystemManager/ArchitecturalTitle/GetArchitecturalTitleAdd",
              this.form
            )
            .then((r) => {
              if ((r.status == 200) & r.data) {
                this.$message("添加成功");
                this.dialogZiDianAddVisible = false;
                this.show();
              }
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
      // this.$axios
      //   .post(
      //     "http://localhost:20932/api/SystemManager/ArchitecturalTitle/GetArchitecturalTitleAdd",
      //     this.form
      //   )
      //   .then((r) => {
      //     if ((r.status == 200) & r.data) {
      //       this.$message("添加成功");
      //       this.dialogZiDianAddVisible = false;
      //       this.show();
      //     }
      //   });
    },
    handleDel() {
      var list = this.$refs["multipleTable"].selection;
      var ids = [];
      if (list.length === 0) {
        this.$message("至少选中一个");
        return false;
      }
      list.forEach((r) => {
        ids.push(r.atle_id);
      });
      if (!confirm("确定删除吗？")) {
        return false;
      }
      this.$axios
        .post(
          "http://localhost:20932/api/SystemManager/ArchitecturalTitle/GetArchitecturalTitleDel?ids=" +
            ids
        )
        .then((r) => {
          if ((r.status == 200) & r.data) {
            this.$message("删除成功");
            this.show();
          }
        });
    },
  },
};
</script>